//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.domain.NoticeReadVo;
import com.ruoyi.system.api.domain.SwglAnnouncement;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.domain.vo.AnnounceVo;
import com.ruoyi.system.service.ISwglAnnouncementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(
        tags = {"公示公告，汇集和维护所内管理实务Controller"}
)
@RestController
@RequestMapping({"/announcement"})
public class SwglAnnouncementController extends BaseController {
    @Autowired
    private ISwglAnnouncementService swglAnnouncementService;
    @Autowired
    private TokenService tokenService;

    @ApiOperation("查询公示公告，汇集和维护所内管理实务列表")
    @RequiresPermissions({"system:announcement:list"})
    @PostMapping({"/list"})
    public TableDataInfo list(@RequestBody SwglAnnouncement swglAnnouncement) {
        PageDomain pageDomain = new PageDomain();
        SysUser sysUser = this.tokenService.getLoginUser().getSysUser();
        BeanUtils.copyProperties(swglAnnouncement, pageDomain);
        this.startPage(pageDomain);
        List<SwglAnnouncement> list = this.swglAnnouncementService.selectSwglAnnouncementList(swglAnnouncement);
        return this.getDataTable(list);
    }

    @ApiOperation("滚动显示的公告列表")
    @GetMapping({"/showList"})
    public TableDataInfo showList() {
        this.startPage();
        List<SwglAnnouncement> list = this.swglAnnouncementService.selectSwglAnnouncementShowList();
        return this.getDataTable(list);
    }

    @ApiOperation("公告已读人员列表")
    @PostMapping({"/showIsReadUser"})
    public AjaxResult showIsReadUser(@RequestBody NoticeReadVo noticeReadVo) {
        return AjaxResult.success(this.swglAnnouncementService.selectIsReadUser(noticeReadVo));
    }

    @ApiOperation("根据类型显示公告列表")
    @GetMapping({"/showTypeList"})
    public AnnounceVo showTypeList() {
        AnnounceVo announceVo = this.swglAnnouncementService.selectSwglAnnouncementListByType();
        return announceVo;
    }

    @ApiOperation("根据紧急程度显示公告列表")
    @GetMapping({"/showEmergencyList"})
    public AnnounceVo showEmergencyList() {
        AnnounceVo announceVo = this.swglAnnouncementService.selectSwglAnnouncementListByEmergencyLevel();
        return announceVo;
    }

    @ApiOperation("导出公示公告，汇集和维护所内管理实务列表")
    @RequiresPermissions({"system:announcement:export"})
    @Log(
            title = "公示公告，汇集和维护所内管理实务",
            businessType = BusinessType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, SwglAnnouncement swglAnnouncement) {
        List<SwglAnnouncement> list = this.swglAnnouncementService.selectSwglAnnouncementList(swglAnnouncement);
        ExcelUtil<SwglAnnouncement> util = new ExcelUtil(SwglAnnouncement.class);
        util.exportExcel(response, list, "公示公告，汇集和维护所内管理实务数据");
    }

    @ApiOperation("获取公示公告，汇集和维护所内管理实务详细信息")
    @RequiresPermissions({"system:announcement:query"})
    @PostMapping({"/getInfo"})
    public AjaxResult getInfo(@RequestBody SwglAnnouncement swglAnnouncement) {
        return AjaxResult.success(this.swglAnnouncementService.selectSwglAnnouncementByAnnouceId(swglAnnouncement.getAnnouceId()));
    }

    @ApiOperation("新增公示公告，汇集和维护所内管理实务")
    @RequiresPermissions({"system:announcement:add"})
    @Log(
            title = "公示公告，汇集和维护所内管理实务",
            businessType = BusinessType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody SwglAnnouncement swglAnnouncement) {
        return this.toAjax(this.swglAnnouncementService.insertSwglAnnouncement(swglAnnouncement));
    }

    @ApiOperation("修改公示公告，汇集和维护所内管理实务")
    @RequiresPermissions({"system:announcement:edit"})
    @Log(
            title = "公示公告，汇集和维护所内管理实务",
            businessType = BusinessType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody SwglAnnouncement swglAnnouncement) {
        return this.toAjax(this.swglAnnouncementService.updateSwglAnnouncement(swglAnnouncement));
    }

    @ApiOperation("删除公示公告，汇集和维护所内管理实务")
    @RequiresPermissions({"system:announcement:remove"})
    @Log(
            title = "公示公告，汇集和维护所内管理实务",
            businessType = BusinessType.DELETE
    )
    @PostMapping({"/remove"})
    public AjaxResult remove(@RequestBody AnnounceVo announceVo) {
        String[] strArr = announceVo.getAnnouceIds().split(",");
        return this.toAjax(this.swglAnnouncementService.deleteSwglAnnouncementByAnnouceIds(strArr));
    }
}
